package com.ruoyi.common.utils.qrKey;

import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.spring.SpringUtils;


import java.util.concurrent.TimeUnit;

/**
 * 注册二维码工具类
 */
public class CacheQrKeyUtils {
    /**
     * 分隔符
     */
    public static final String SEPARATOR = ",";

    /**
     *
     * @param key       参数键
     * @param loginUser 当前登录的用户信息
     */
    public static void setQrCache(String key, LoginUser loginUser) {
        SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), loginUser,5, TimeUnit.HOURS);
    }

    /**
     *
     * @param key 参数键
     */
    public static LoginUser getQrCache(String key) {
        if (key == null || key.length() == 0) {
            return null;
        }
        LoginUser loginUser = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
        return loginUser;
    }


    /**
     *
     * @param key 参数键
     */
    public static boolean removeQrCache(String key) {
       return SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key));
    }



    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    public static String getCacheKey(String configKey) {
        return CacheConstants.BIND_QR_KEY + configKey;
    }
}
